﻿using System.Diagnostics;
using System.Text;

namespace TfsCloudDeploy.Tasks
{
    /// <summary>
    /// A simple wrapper class for asynchronously capturing multiple redirected outputs from System.Console.
    /// See MSDN documentation on System.Diagnostics.Process.StandardOutput for details.
    /// </summary>
    public class ProcessOutput
    {
        StringBuilder standardOutput;
        StringBuilder standardError;

        internal ProcessOutput()
        {
            standardOutput = new StringBuilder();
            standardError  = new StringBuilder();
        }

        internal string StandardOutput
        {
            get { return standardOutput.ToString(); }
        }

        internal string StandardError
        {
            get { return standardError.ToString(); }
        }

        internal void OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            standardOutput.AppendFormat("{0}\r\n", e.Data);
        }

        internal void ErrorDataReceived(object sender, DataReceivedEventArgs e)
        {
            standardError.AppendFormat("{0}\r\n", e.Data);
        }
    }
}